<?php
/**
 * label表
 */

namespace app\common\model\mysql;
use think\Model;
class Label extends Model
{
    protected $name = 'label';
    protected $autoWriteTimestamp = true;


    /**
     * 根据条件查询信息
     * @param array $where 查询条件
     * @param array $whereOr // 双条件
     * @param array $displayField // 显示的字段
     * @param array $hideField // 隐藏的字段
     * @param array $order // 排序
     * @return array|Model|PhoneBook|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getFindModel(array $where=[], array $whereOr=[], array $displayField=[], array $hideField=[], array $order=[]){
        try{
            return $this->where($where)
                ->where(function ($query) use ($whereOr) { $query->whereOr($whereOr); })
                ->field($displayField)
                ->withoutField($hideField)
                ->order($order)
                ->find();
        }catch (\Exception $e){
            exception($e,'mysql.getFindModel');
        }
    }

    /**
     * 列表数据
     * @param string $where
     * @return UserInfo[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getListData($where=[],$displayField=[],$hideField=[],$order=[],$page=1,$limit=10)
    {
        try{
            if($page == -1 || $limit == -1) {
                $result = $this->where($where)
                    ->field($displayField)
                    ->withoutField($hideField)
                    ->order($order)
                    ->select();
            }else{
                $result = $this->where($where)
                    ->field($displayField)
                    ->withoutField($hideField)
                    ->order($order)
                    ->paginate([
                        'list_rows'=>$limit,
                        'page'=>$page
                    ]);
            }
            return $result;
        }catch (\Exception $e){
            exception($e,'mysql.getListData');
        }
    }
    /**
     * 更新信息
     * @param $query //更新条件
     * @return array|false|void
     */
    public function updateDataModel($query){
        try{
            if(!is_array($query)){
                return false;
            }
            return $this->update($query);
        }catch (\Exception $e){
            exception($e,'mysql.updateDataModel');
        }
    }

    public function multiplePrimaryKeys($where){
        try{
            return $this->select($where);
        }catch (\Exception $e){
            exception($e,'mysql.multiplePrimaryKeys');
        }
    }
}
